<?php

class Application_Model_DbTable_Productos extends Zend_Db_Table_Abstract
{

    protected $_name = 'productos';

	public function getProductos() {
		$select  = $this->_db->select()
			->from($this->_name)
			->joinLeft('categorias','categorias.id_categoria = productos.id_categoria',array('categoria'=>'nombre'));
		// print_r($select->__toString());die();

		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}
	
	public function getProductosFromId($id) {
		$select  = $this->_db->select()
			->from($this->_name)->where($this->_name.'.id_producto = ?', $id);
		
		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}
	
	public function getImgNameFromId($idProducto) {
		$select  = $this->_db->select()
			->from($this->_name,array('imageName' => 'imagen'))
			->where($this->_name.'.id_producto = ?', $idProducto);

		$result = $this->getAdapter()->fetchAll($select);

		return $result[0]['imageName'];
	}

	public function getTotalProductos() {
		$select  = $this->_db->select()
			->from($this->_name,array("total"=>"COUNT(*)"));
		// print_r($select->__toString());die();

		$result = $this->getAdapter()->fetchAll($select);

		return $result[0]['total'];
	}
}

